package com.game.load;

import com.dats.db.NameKeyUnit;
import com.dats.entity.CacheBean;
import com.game.dao.DatSDao;
import com.game.hot.Manager;
import com.game.pool.DataPool;
import com.game.db.NameKey;
import com.game.util.LogUtil;

import java.util.List;

/**
 * @author sig
 * @since 2016/9/27
 */
public class LoadMg implements com.dats.i.LoadI, LoadI {

    @Override
    public <T extends CacheBean> void put2DelList(T t) {
        if (null == t) return;
        t.setDel(true);
        DataPool.saveDelList.add(t);
    }

    @Override
    public <T extends CacheBean> void put2DelList(List<T> list) {
        DataPool.saveDelList.addAll(list);
    }

    @Override
    public void saveDel() {
        if (DataPool.saveDelList.isEmpty()) return;
        DatSDao.saveDelList(DataPool.saveDelList);
        LogUtil.console.info("The amount of deleted data: " +
                DataPool.saveDelList.size());
        DataPool.saveDelList.clear();
    }

    @Override
    public void delete() {
        for (NameKeyUnit tmp : NameKey.getClassMap().values())
            DatSDao.delete(tmp.getTableName());
    }

    @Override
    public void loadGameData() {
        Manager.getRoleMg().loadRole();
    }
}
